#! /bin/sh

hostOsType=$(uname -s)

dirLib=""

for arg in "${@}" ; do
	case ${arg} in
		--lib-dir=*) dirLib="$(echo ${arg} | sed 's;--lib-dir=;;')" ;;
		*)
			echo "unknown option: ${arg}"
		;;
	esac
done

if [ ! -z "${dirLib}" ] ; then

	/bin/rm -f ${dirLib}/ld.so.cache

	case "${hostOsType}" in
		FreeBSD)
			/sbin/ldconfig -i -f ${dirLib}/ld.so.cache ${dirLib}
		;;
		Linux)
			/sbin/ldconfig -f ${dirLib}/ld.so.conf -C ${dirLib}/ld.so.cache ${dirLib} > /dev/null 2> /dev/null
		;;
		SunOS)
			/bin/crle -64 -c ${dirLib}/ls.so.conf -l ${dirLib}
		;;
		CYGWIN*)
			cd ${dirLib}
			ls -1 cyg*.dll > dlls.txt
			/bin/rebaseall -v -p -T ./dlls.txt > /dev/null 2>&1
			/bin/rm ./dlls.txt
		;;
		Darwin)
			echo "Operating system does not support dynamic library indexing."
		;;
		*)
			echo "Unknown host operating system type!"
			exit 1
		;;
	esac
else
	echo "Core settings not set!"
	exit 1
fi

exit 0
